<?php global $has_permit; ?>
<div class="std_header auto_height">
    <div class="left">
        <strong><?php echo $module['title']; ?></strong>
    </div>
    <div class="right">
    <button class="gray_btn" onclick="admin_site_privilege.create_new()"><span>Thêm mới</span></button>
</div>
</div>
<div class="db_left bl">
    <?php $this->load->view('site/admin/side_block'); ?>
</div>
<div class="db_right bl">
    <?php if ($has_permit) :?>
    <div id="privilege_management">
        <div id="tab_store" class="tab_container">
            <ul>
                <li id="active_tab_list"><a href="#tab_list"><span>Danh sách quyền hạn</span></a></li>
                <li id="active_tab_edit"><a href="#tab_edit"><span>Thông tin quyền hạn</span></a></li>
                <li id="active_tab_system"><a href="#tab_system"><span>Danh sách quyền hệ thống</span></a></li>
            </ul>
            <div id="tab_list">
                <?php if (count($collection) != 0) : ?>
                <?php $this->load->view('site/privilege/message'); ?>
                <form action="<?php echo site_url('admin/site/privilege/index', true); ?>" method="post" id="frm_privilege_gridview">
                    <div class="block">
                        <table class="gridview" width="100%" cellpadding="0" cellspacing="0" border="0">
                            <thead>
                            <tr>
                                <td><b>ID</b></td>
                                <td><b>Tên</b></td>
                                <td><b>URL</b></td>
                                <td><b>Thao tác</b></td>
                            </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($collection as $privilege) : ?>
                            <tr>
                                <input type="hidden" value="" class="edit_url" />
                                <td width="30px" valign="top">
                                    <?php echo $privilege->id; ?>
                                </td>
                                <td valign="top">
                                    <?php echo $privilege->name; ?>
                                </td>
                                <td valign="top">
                                    <?php echo $privilege->url; ?>
                                </td>
                                <td valign="top">
                                    <p>
                                        <a class="ajax_link icon icon_edit" data="{id:<?php echo $privilege->id; ?>}" selector="#tab_edit" item="#active_tab_edit a" href="<?php echo site_url('admin/site/privilege/ajax_edit/id/' . $privilege->id, true); ?>">
                                        </a>
                                        <a class="icon icon_delete" href="<?php echo site_url('admin/site/privilege/delete/id/' . $privilege->id, true); ?>" onclick="return confirm('Bạn muốn xóa quyền hạn này?')">
                                        </a>
                                    </p>
                                </td>
                            </tr>
                                <?php endforeach; ?>
                            </tbody>
                            <tfoot>

                            </tfoot>
                        </table>
                    </div>
                </form>
                <?php else : ?>
                <div class="error_message corner">Không có quyền hạn nào</div>
                <?php endif; ?>
            </div>
            <div id="tab_edit">
                <form id="frm_privilege_edit" method="POST" action="<?php echo $save_action; ?>">
                    <div class="clearfix auto_height mb_10">
                        <button class="gray_btn active_item" type="button" item="#active_tab_list a"><span>Về danh sách</span></button>
                        <button class="gray_btn" type="submit"><span>Lưu lại</span></button>
                        <button class="gray_btn" type="reset"><span>Nhập lại</span></button>
                    </div>
                    <div class="form_block">
                        <div class="block_header">
                            Thông tin căn bản
                        </div>
                        <div class="block_content">
                            <table cellpadding="0px" cellspacing="0px">
                                <tr>
                                    <td class="frm_label">Tên quyền hạn(*)</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input required" name="data[name]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Quyền truy cập(*)</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input required" name="data[url]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Mô tả</td>
                                    <td class="frm_field">
                                        <textarea name="data[description]"></textarea>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="clearfix auto_height">
                        <button class="gray_btn active_item" type="button" item="#active_tab_list a"><span>Về danh sách</span></button>
                        <button class="gray_btn" type="submit"><span>Lưu lại</span></button>
                        <button class="gray_btn" type="reset"><span>Nhập lại</span></button>
                    </div>
                </form>
            </div>
            <div id="tab_system">
                <div class="lst_group">
                    <?php $index = 1; foreach ($system_privileges as $group_privilege) :?>
                    <div class="db_side_block">
                        <div class="db_side_header">
                            <label>
                                <strong>#<?php echo $index; ?>. <?php echo $group_privilege['name']; ?></strong>
                            </label>
                        </div>
                        <div class="db_inner_content">
                            <ul>
                                <?php $system_index = 1; foreach ($group_privilege['children'] as $system_privilege) :?>
                                <li>
                                    <label>
                                        <span class="icon icon_privilege"></span>
                                        <strong>[#<?php echo $system_index; ?>]. <?php echo $system_privilege['name']; ?></strong>
                                    </label>
                                </li>
                                <?php $system_index++; ?>
                                <?php endforeach; ?>
                            </ul>
                        </div>
                    </div>
                    <?php $index++; ?>
                    <?php endforeach; ?>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
    <?php else :?>
    <?php $this->load->view('layouts/restricted'); ?>
    <?php endif; ?>
</div>
<div class="clearfix"></div>
<script type="text/javascript">
    $("#frm_privilege_edit").validate();
</script>
<script type="text/javascript" src="<?php echo BASE_URL; ?>js/admin/site/privilege/function.js"></script>